import { tool } from "@langchain/core/tools";
import { z } from "zod";
import { ipcRenderer } from "electron";


const searchTool = tool(
  async ({ query }: { query: string }) :Promise<string> => {
    const searchResult= await ipcRenderer.invoke(
      "llm-search-tool-result",
      query
    );
    console.log("searchResult=", searchResult);
    return JSON.stringify(searchResult);
  },
  {
    name: "search_tool",
    description: "用于获取相关文章的搜索结果",
    schema: z.object({
      query: z.string().describe("搜索关键词"),
    }),
    verbose: true,
  }
);

export {searchTool}